package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.InsertQuestionBean;
import com.example.administrator.yuejian2.service.InsertQuestionService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;
import static com.example.administrator.yuejian2.other.Url.URL3;

public class InsertQuestionModel {
    private Retrofit retrofit;
    private InsertQuestionService insertQuestionService;
    public InsertQuestionModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL3)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        insertQuestionService=retrofit.create(InsertQuestionService.class);
    }

    public void insertQuestion(String user_id, String master_id, String question_content, final RetrofitListener listener)
    {
        Call<InsertQuestionBean> call=insertQuestionService.insertQuestion(user_id,master_id,question_content);
        call.enqueue(new Callback<InsertQuestionBean>() {
            @Override
            public void onResponse(Call<InsertQuestionBean> call, Response<InsertQuestionBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<InsertQuestionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }


}
